package com.molin.extensionTest.getClassNameModel;

import java.lang.reflect.Constructor;

public class Demo2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        Class clazz = Class.forName("com.molin.extensionTest.getClassNameModel.Student");
//        method01(clazz);
//        method02(clazz);
//        method03(clazz);
//        method4(clazz);
    }

    public static void method4(Class clazz) throws NoSuchMethodException {
        //可以获取私有的构造方法
        Constructor declaredConstructor = clazz.getDeclaredConstructor(String.class);
        System.out.println(declaredConstructor);
    }

    public static void method03(Class clazz) throws NoSuchMethodException {
        //跟构造方法的形参保存一致
        Constructor constructor = clazz.getConstructor();
        System.out.println(constructor);
        Constructor constructor1 = clazz.getConstructor(String.class,int.class);
        System.out.println(constructor1);
    }


    public static void method02(Class clazz) {
        //获取所有的构造方法
        Constructor[] declaredConstructors = clazz.getDeclaredConstructors();
        for (Constructor declaredConstructor : declaredConstructors) {
            System.out.println(declaredConstructor);
        }
    }

    public static void method01(Class clazz) {
        //返回所有公共的构造方法
        Constructor[] constructors = clazz.getConstructors();
        for (Constructor constructor : constructors) {
            System.out.println(constructor);
        }
    }
}
